//
//  CheckBankCardMessage.m
//  NewProject
//
//  Created by yaoqi yaoqi on 2018/1/5.
//  Copyright © 2018年 duandonggang. All rights reserved.
//

#import "WriteBankCardMessage.h"
#import "YanZhengMaBtn.h"
#define LableHight 49
@interface WriteBankCardMessage ()<UITextFieldDelegate>{
    NSString *str;
    UIButton *selectBtn,*unselectBtn;
    NSNumber *reviceSexBtnMessage;
}
@property(nonatomic,strong)UITextField *receiveNameField;
@property(nonatomic,strong)UITextField *receiveAddressField;
@property(nonatomic,strong)UITextField *phoneNumberField;
@property(nonatomic,strong)NSMutableArray *regionIdMuArray;
@property(nonatomic,strong)UITextField *addressLable;
@property(nonatomic,strong)UITextField *zipField;
@property(nonatomic,strong)YanZhengMaBtn *yanZhengMaBtn;
@end

@implementation WriteBankCardMessage

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setNavTitleText:@"收款账户"];
   
    [self content];
    
}
-(void)content{
    reviceSexBtnMessage=[NSNumber numberWithInteger:1];
    float space = 15;
    float lableW = 62 + 15;
    //整体view
    UIView * contentV = [[UIView alloc]init];
    contentV.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:contentV];
    //收货人
    UILabel *nickName=[[UILabel alloc]init];
    //    nickName.textAlignment = NSTextAlignmentRight;
    nickName.font=MediumFont(14);
    nickName.text=@"银行";
    nickName.frame=CGRectMake(space, 0, lableW,LableHight);
    [contentV addSubview:nickName];
    self.receiveNameField=[[UITextField alloc]initWithFrame:CGRectMake(nickName.right+10, 0, KScreenWidth-nickName.right-30, LableHight)];
    self.receiveNameField.placeholder=@"建设银行";
    self.receiveAddressField.textColor = rgb_153;
    self.receiveNameField.font=MediumFont(14);
    self.receiveNameField.textAlignment = NSTextAlignmentRight;
    [contentV addSubview:self.receiveNameField];
    //线
    UIView *view=[[UIView alloc]initWithFrame:CGRectMake(15, nickName.bottom, KScreenWidth - 30,0.5)];
    view.backgroundColor=rgb(232,232,232);
    [contentV addSubview:view];
    //联系电话
    UILabel *nickName2=[[UILabel alloc]init];
    //    nickName2.textAlignment = NSTextAlignmentRight;
    nickName2.font=MediumFont(14);
    nickName2.text=@"所在支行";
    nickName2.frame=CGRectMake(space, view.bottom, lableW,LableHight);
    [contentV addSubview:nickName2];
    self.phoneNumberField=[[UITextField alloc]initWithFrame:CGRectMake(nickName2.right+10, view.bottom, KScreenWidth-nickName2.right-30, LableHight)];
    self.phoneNumberField.placeholder=@"中山东路支行";
    self.phoneNumberField.textColor = rgb_153;
    self.phoneNumberField.textAlignment = NSTextAlignmentRight;
    self.phoneNumberField.font=MediumFont(14);
    self.phoneNumberField.keyboardType=UIKeyboardTypeNumberPad;
    [contentV addSubview:self.phoneNumberField];
    //添加一个view
    UIView *view2=[[UIView alloc]initWithFrame:CGRectMake(space, self.phoneNumberField.bottom, KScreenWidth-space*2,0.5)];
    view2.backgroundColor=rgb(232,232,232);;
    [contentV addSubview:view2];
    //邮政
    UILabel *zipLable=[[UILabel alloc]init];
    //    zipLable.textAlignment = NSTextAlignmentRight;
    zipLable.font=MediumFont(14);
    zipLable.text=@"卡号";
    zipLable.frame=CGRectMake(space, view2.bottom, lableW,LableHight);
    [contentV addSubview:zipLable];
    self.zipField = [[UITextField alloc]initWithFrame:CGRectMake(zipLable.right+10, view2.bottom, KScreenWidth-zipLable.right-30, LableHight)];
    self.zipField.placeholder=@"请输入卡号";
    self.zipField.font=MediumFont(14);
    self.zipField.textColor = rgb_153;
    self.zipField.textAlignment = NSTextAlignmentRight;
    self.zipField.keyboardType=UIKeyboardTypeNumberPad;
    [contentV addSubview:self.zipField];
    
    //添加一个view
    UIView *zipView=[[UIView alloc]initWithFrame:CGRectMake(space, self.zipField.bottom, KScreenWidth-space*2,0.5)];
    zipView.backgroundColor=rgb(232,232,232);
    [contentV addSubview:zipView];
    //省市区
    UIView *view5=[[UIView alloc]initWithFrame:CGRectMake(0, zipView.bottom, KScreenWidth, LableHight)];
    view5.backgroundColor=[UIColor whiteColor];
    [contentV addSubview:view5];
    UILabel *lable3=[[UILabel alloc]init];
    //    lable3.textAlignment = NSTextAlignmentRight;
    lable3.font=MediumFont(14);
    lable3.text=@"手机号";
    lable3.frame=CGRectMake(space, 0, lableW, LableHight);
    [view5 addSubview:lable3];
    self.addressLable=[[UITextField alloc]initWithFrame:CGRectMake(lable3.right+10, 0, KScreenWidth-lable3.right-40, LableHight)];
    self.addressLable.text = @"手机号";
    self.addressLable.placeholder=@"请输入卡号";
    self.addressLable.font=MediumFont(14);
    self.addressLable.textColor = rgb_153;
    self.addressLable.textAlignment = NSTextAlignmentRight;
    [view5 addSubview:self.addressLable];
    //添加一个view
    UIView *view3=[[UIView alloc]initWithFrame:CGRectMake(space, view5.bottom, KScreenWidth-space*2,.5f)];
    view3.backgroundColor=rgb(232,232,232);
    [contentV addSubview:view3];
    //收货地址
    UILabel *nickName1=[[UILabel alloc]init];
    //    nickName1.textAlignment = NSTextAlignmentRight;
    nickName1.font=MediumFont(14);
    nickName1.text=@"验证码";
    nickName1.frame=CGRectMake(space, view3.bottom, lableW,LableHight);
    [contentV addSubview:nickName1];
    self.receiveAddressField=[[UITextField alloc]initWithFrame:CGRectMake(nickName1.right+10, view3.bottom, KScreenWidth-nickName1.right-30 - 70, LableHight)];
    self.receiveAddressField.placeholder=@"请输入验证码";
    self.receiveAddressField.textAlignment = NSTextAlignmentRight;
    self.receiveAddressField.font=MediumFont(14);
    self.receiveAddressField.textColor = rgb_153;
    [contentV addSubview:self.receiveAddressField];
    
    self.yanZhengMaBtn=[YanZhengMaBtn buttonWithType:UIButtonTypeCustom];
    self.yanZhengMaBtn.frame = CGRectMake(KScreenWidth - 10 - 60, nickName1.yv , 60, LableHight);
    [self.yanZhengMaBtn setTitle:@"获取" forState: UIControlStateNormal ];
    [self.yanZhengMaBtn setTitleColor:rgb(255,138,10) forState:UIControlStateNormal];
    self.yanZhengMaBtn.titleLabel.font=MediumFont(14);
    self.yanZhengMaBtn.DaoJiShitime=60;
    self.yanZhengMaBtn.againColor=[UIColor whiteColor];
    [self.yanZhengMaBtn addTarget:self action:@selector(sendCord:) forControlEvents:UIControlEventTouchUpInside];
    [contentV addSubview:self.yanZhengMaBtn];

    //添加一个view
    UIView *view4=[[UIView alloc]initWithFrame:CGRectMake(space, nickName1.bottom, KScreenWidth-space*2,0.5)];
    view4.backgroundColor=rgb(232,232,232);
    [contentV addSubview:view4];
    
    
    
    contentV.frame = CGRectMake(0, Height_NavBar + 10, KScreenWidth, view4.bottom);
    
    UIButton *OKBtn=[[UIButton alloc]initWithFrame:CGRectMake(50,KScreenHeight - Height_Indicator - 44 - 60 , KScreenWidth - 100, 44)];
    [OKBtn setTitle:@"保存" forState:UIControlStateNormal];
    OKBtn.titleLabel.font=MediumFont(18);
    [OKBtn setBackgroundImage:[UIImage imageNamed:@"affirm_img_2"] forState:0];
    OKBtn.layer.cornerRadius=5;
    OKBtn.layer.masksToBounds=YES;
    [OKBtn addTarget:self action:@selector(commintNewAddress:) forControlEvents:UIControlEventTouchUpInside ];
    [self.view addSubview:OKBtn];
}
#pragma mark- 是/否按钮点击事件
-(void)selectorSex:(UIButton*)button{
    selectBtn.selected=!button.selected;
    
}
#pragma mark- 省市区手势事件
-(void)clickedHandleChooseAddress{
    [self.phoneNumberField resignFirstResponder];
    [self.receiveNameField resignFirstResponder];
    [self.receiveAddressField resignFirstResponder];
    //    DizhiChoseView *dizhiChoseView = [[DizhiChoseView alloc]initWithFrame:CGRectMake(0, 0, KScreenWidth, KScreenHeight)];
    //    dizhiChoseView.delegate =self;
    //    [self.view addSubview:dizhiChoseView];
}
#pragma mark - addressChooseDelegate
-(void)choseEndClicked:(NSArray*)ary{
    str = @"";
    str=[NSString stringWithFormat:@"%@%@%@",ary[0][@"regionName"],ary[1][@"regionName"],ary[2][@"regionName"]];
    self.addressLable.text = [NSString stringWithFormat:@"%@ %@ %@",ary[0][@"regionName"],ary[1][@"regionName"],ary[2][@"regionName"]];
    [self.regionIdMuArray addObject:ary[0][@"regionId"]];
    [self.regionIdMuArray addObject:ary[1][@"regionId"]];
    [self.regionIdMuArray addObject:ary[2][@"regionId"]];
}
#pragma mark- 点击确认按钮
-(void)commintNewAddress:(UIButton *)button{
    if ((self.receiveNameField.text.length==0)||(self.phoneNumberField.text.length==0)||(self.receiveAddressField.text.length==0)||(self.addressLable.text.length==0)) {
        //        [[iToast makeText:@"请完善您的信息"] show];
    }else{
        //检验手机号是否正确
        NSString *regex = @"^1[3|4|5|7|8][0-9]\\d{8}$";
        NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", regex];
        if (![predicate evaluateWithObject:self.phoneNumberField.text]) {
            //                [[iToast makeText:@"手机号有误，请检查重试!"] show];
            return;
        }
        
        //输入框都不为空时,进行地址修改
        NSMutableDictionary *parameterDict = [NSMutableDictionary dictionary];
        if(self.regionIdMuArray.count != 0) {
            NSLog(@"%@",self.regionIdMuArray);
            [parameterDict setObject:[self.regionIdMuArray objectAtIndex:0] forKey:@"provinceId"];
            [parameterDict setObject:[self.regionIdMuArray objectAtIndex:1] forKey:@"cityId"];
            [parameterDict setObject:[self.regionIdMuArray objectAtIndex:2] forKey:@"districtId"];
        }
        [parameterDict setObject:self.receiveNameField.text forKey:@"consignee"];
        [parameterDict setObject:self.phoneNumberField.text forKey:@"phone"];
        //详细地址
        [parameterDict setObject:self.receiveAddressField.text forKey:@"detailedAddress"];
        //地址拼接
        str=[NSString stringWithFormat:@"%@%@",str,self.receiveAddressField.text];
        [parameterDict setObject:reviceSexBtnMessage forKey:@"isDefault"];
        //提交fullAddress
        [parameterDict setObject:str forKey:@"fullAddress"];
        
        
    }
}
-(void)sendCord:(YanZhengMaBtn *)btn{
    [btn daoJiShi];
}
#pragma mark- 懒加载
-(NSMutableArray *)regionIdMuArray{
    if (!_regionIdMuArray) {
        _regionIdMuArray=[NSMutableArray arrayWithCapacity:30];
    }
    return _regionIdMuArray;
}
@end
